/*
 * Copyright (c) 2006-2024, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-22     RT-Thread    first version
 */

#include <rtthread.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
//zijijia
#include <board.h>
#include <rtdevice.h>
# define LED1_PIN   GET_PIN(B,5)
#include <drv_soft_i2c.h>
#include <arpa/inet.h>  /* 包含 ip_addr_t 等地址相关的头文件 */
#include <netdev.h>     /* 包含全部的 netdev 相关操作接口函数 */
#include <ntp.h>



extern int sht30_collect(void);

int main(void)
{
    int count = 1;

    rt_pin_mode(LED1_PIN,PIN_MODE_OUTPUT);

    //sht30_collect();

    while (count++)
    {

        rt_pin_write(LED1_PIN,count%2);
        //LOG_D("Hello RT-Thread!");
        rt_thread_mdelay(1000);
    }

    //获取网卡对象
    struct netdev* net = netdev_get_by_name("esp0");

    //阻塞判断当前网络是否正常连接
    while(netdev_is_internet_up(net) != 1)
    {
       rt_thread_mdelay(200);
    }
    //提示当前网络已就绪
    rt_kprintf("network is ok!\n");

    //NTP自动校对
    time_t cur_time;
    cur_time = ntp_sync_to_rtc(NULL);
    if (cur_time)
    {
        rt_kprintf("Cur Time: %s", ctime((const time_t*) &cur_time));
    }
    else
    {
        rt_kprintf("NTP sync fail.\n");
    }

    return RT_EOK;
}


